package com.bestcem.xm.user.grpc.service.converter.strategy;

import com.bestcem.xm.common.core.uitls.GrpcDateUtil;
import com.google.protobuf.Timestamp;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import java.util.Date;

/**
 * 公共转换策略
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/6/29 17:34
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CommonStrategy {

    public static String stringStrategy(String str) {
        return StringUtils.isBlank(str) ? null : str;
    }

    public static Timestamp dateToTimestam(Date value) {
        return GrpcDateUtil.getTimestamp(value);
    }

    public static Boolean integerToBoolean(Integer value) {
        return NumberUtils.INTEGER_ZERO.equals(value);
    }

    public static Timestamp dateToGrpcTimestamp(Date value) {
        return GrpcDateUtil.getTimestamp(value);
    }

}
